package aptech.eproject.logictics.db;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;

/**
 * The persistent class for the VEHICLE database table.
 * 
 */
@Entity
@Table(name = "VEHICLE")
@NamedQueries({
    @NamedQuery(name = "findVehicles", query = "SELECT v FROM Vehicle v WHERE v.isDeleted = FALSE AND v.branch.branchId = ?1"),
    @NamedQuery(name = "findVehicleById", query = "SELECT v FROM Vehicle v WHERE v.isDeleted = FALSE  AND v.vehicleId = ?1"),
    @NamedQuery(name = "findVehiclesByType", query = "SELECT v FROM Vehicle v WHERE v.isDeleted = FALSE AND v.branch.branchId = ?1 AND v.type LIKE ?2")})
public class Vehicle implements Serializable {

    private static final long serialVersionUID = 1L;
    private String vehicleId;
    private boolean isDeleted;
    private VehicleStatus status;
    private String type;
    private int weightLimit;
    private Set<Trip> trips;
    private Branch branch;

    public Vehicle() {
    }

    @Id
    @Column(name = "VEHICLE_ID", nullable = false)
    public String getVehicleId() {
        return this.vehicleId;
    }

    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }

    @Column(name = "IS_DELETED", nullable = true)
    public boolean getIsDeleted() {
        return this.isDeleted;
    }

    public void setIsDeleted(boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "STATUS", nullable = true)
    public VehicleStatus getStatus() {
        return status;
    }

    public void setStatus(VehicleStatus status) {
        this.status = status;
    }

    @Column(name = "TYPE", nullable = false)
    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Column(name = "WEIGHT_LIMIT", nullable = false)
    public int getWeightLimit() {
        return this.weightLimit;
    }

    public void setWeightLimit(int weightLimit) {
        this.weightLimit = weightLimit;
    }

    //bi-directional many-to-one association to Trip
    @OneToMany(mappedBy = "vehicle", fetch = FetchType.EAGER)
    public Set<Trip> getTrips() {
        return this.trips;
    }

    public void setTrips(Set<Trip> trips) {
        this.trips = trips;
    }

    public Trip addTrip(Trip trip) {
        getTrips().add(trip);
        return trip;
    }

    public Trip removeTrip(Trip trip) {
        getTrips().remove(trip);
        trip.setVehicle(null);
        return trip;
    }

    //bi-directional many-to-one association to Branch
    @ManyToOne
    @JoinColumn(name = "BRANCH_ID", nullable = false)
    public Branch getBranch() {
        return this.branch;
    }

    public void setBranch(Branch branch) {
        this.branch = branch;
    }
}
